<?php
class GUI{
	function alert($msg){
		$alert = '<script language="javascript"> alert("'.$msg.'");</script>';
		echo $alert;
	}
	function close(){
		$close = '<script language="javascript"> window.close();</script>';
		echo $close;
	}
	function redir($url){
		$redir = '<script language="javascript"> location.href="'.$url.'";</script>';
		echo $redir;
		exit();
	}
	function refresh($timeout,$url){
		echo '<meta http-equiv="refresh" content="'.$timeout.' '.$url.'" />';
		exit();
	}
	function simple_execsql($sql){
		$rs = mysql_query($sql) or $this->redir('?mod=home');
		return $rs;
	}
	function simple_recordset($sql){
		if($sql){
			$rs = mysql_query($sql) or $this->redir('?mod=home');
			$row =  mysql_fetch_array($rs);	
			return $row;
		}
	}
	function rent_day($control_form_name,$event){
		$rent = '<select name="'.$control_form_name.'" '.$event.'>';
		for($i=1;$i<=31;$i++){
			$rent.= '<option value="'.$i.'">'.$i.'</option>';
		}
		$rent.= '</select>';
		return $rent;
	}
	function rent_month($control_form_name,$event){
		$month = array(
				 "January"=>"1", "February"=>"2", "March"=>"3", "April"=>"4", "May"=>"5",
				 "June"=>"6", "July"=>"7", "August"=>"8", "September"=>"9", "October"=>"10",
				 "November"=>"11", "December"=>"12");
		$rent = '<select name="'.$control_form_name.'" '.$event.'>';	
		foreach($month as $name=>$index){
			$rent.= '<option value="'.$index.'">'.$name.'</option>';
		}	
		$rent.= '</select>';
		return $rent; 
	}
	function rent_year($control_form_name,$event,$from,$to){
		$rent = '<select name="'.$control_form_name.'" '.$event.'>';
		for($i=$from;$i<=$to;$i++){
			$rent.= '<option value="'.$i.'">'.$i.'</option>';
		}
		$rent.= '</select>';
		return $rent;
	}
	function cutString($str,$maxlen){
		if(strlen($str)>$maxlen){
			$newstr=substr($str,0,$maxlen);
			while(' '!=substr($newstr,-1,1)){
				$maxlen--;
				$newstr=substr($newstr,0,$maxlen);
			}
			return $newstr."...";
		}else
		return $str;
	}
	function cutWord($str,$num_word){
		$end_of_word = array(" ",",",".","!","...");
		$str = trim($str);
		$count = 0; $i = 0;
		$cut_pos = 0;
		while($i<strlen($str) && $count<$num_word){
			if(in_array($str[$i],$end_of_word)){
				$count++; $cut_pos = $i;
			}
			$i++;
		}
		$words = substr($str,0,$cut_pos);
		return $words."...";
	}
	function nl2br_skip_html($string){
		// remove any carriage returns (mysql)
		$string = str_replace("\r", '', $string);
		// replace any newlines that aren't preceded by a > with a <br />
		$string = preg_replace('/(?<!>)\n/', "<br />\n", $string);
		return $string;
	}	
	function __random($min = null, $max = null){
		static $seeded;
		if(!$seeded){
			mt_srand((double)microtime()*1000000);
			$seeded = true;
		}
		if(isset($min) && isset($max)){
			if ($min >= $max) {
				return $min;
			} else {
				return mt_rand($min, $max);
			}
		}else{
			return mt_rand();
		}
	}
	function format_date_time($strdate){
		$_month = array(
				 "Jan"=>"1", "Feb"=>"2", "Mar"=>"3", "Apr"=>"4", "May"=>"5",
				 "Jun"=>"6", "Jul"=>"7", "Aug"=>"8", "Sep"=>"9", "Oct"=>"10",
				 "Nov"=>"11", "Dec"=>"12");
		if(strlen($strdate) == 10 || strlen($strdate) == 19){
			$day = substr($strdate,8,2);
			$month = substr($strdate,5,2);
			$year = substr($strdate,0,4);
			if(strlen($strdate) == 19)	
				$time = substr($strdate,11,8);
			foreach($_month as $text_month=>$index_month){
				if($index_month == $month){
					$month = $text_month;
				}	
			}
			$strdate = "{$month} {$day}, ".$year." ".$time;
		}
		return $strdate;
	}	
	function button_ren($value,$onclick){
		$button = '<table width="77" border="0" cellspacing="0" cellpadding="0">
					  <tr>
						<td width="77" height="18" background="images/butbg.jpg" align="center" style="color:#5F71A5; cursor:pointer" onclick="'.$onclick.'" title="'.$value.'"><div align="center"><b> '.$value.' </b></div></td>
					  </tr>
					</table>';
		return $button;
	}
}
?>